package com.time.client.infra.basic.service.impl;

import com.time.client.infra.basic.entity.Category;
import com.time.client.infra.basic.mapper.CategoryDao;
import com.time.client.infra.basic.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 文章分类表(Categories)表服务实现类
 *
 * @author makejava
 * @since 2025-09-30 15:52:57
 */
@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param categoryId 主键
     * @return 实例对象
     */
    @Override
    public Category queryById(Long categoryId) {
        return this.categoryDao.queryById(categoryId);
    }

    /**
     * 分页查询
     *
     * @param category 筛选条件
     * @return 查询结果
     */
    @Override
    public List<Category> queryAllByCondition(Category category) {
        return this.categoryDao.queryAllByCondition(category);
    }

    /**
     * 新增数据
     *
     * @param category 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insert(Category category) {
        return this.categoryDao.insert(category);
    }

    /**
     * 修改数据
     *
     * @param category 实例对象
     * @return 实例对象
     */
    @Override
    public Integer update(Category category) {
        return this.categoryDao.update(category);
    }

    /**
     * 通过主键删除数据
     *
     * @param categoryId 主键
     * @return 是否成功
     */
    @Override
    public Integer deleteById(Long categoryId) {
        return this.categoryDao.deleteById(categoryId);
    }

    @Override
    public Category queryByCategoryName(String categoryName) {
        return this.categoryDao.queryByCategoryName(categoryName);
    }

    @Override
    public Integer batchDelete(List<Long> ids, int isDeleted) {
        return this.categoryDao.batchDelete(ids, isDeleted);
    }

    @Override
    public List<Category> queryPrimaryCategory() {
        return Optional.ofNullable(categoryDao.queryPrimaryCategory())
                .orElseGet(List::of);
    }

    @Override
    public Integer resetChildCategoryParentId(Long parentId) {
        return this.categoryDao.resetChildCategoryParentId(parentId);
    }

    @Override
    public Integer countAll() {
        return this.categoryDao.countAll();
    }

    @Override
    public List<Category> queryPage(Category category, int start, Integer pageSize) {
        return this.categoryDao.queryPage(category, start, pageSize);
    }

    @Override
    public List<Category> queryByParentId(Long parentId) {
        return this.categoryDao.queryByParentId(parentId);
    }

}
